import Storage from "web-storage-cache"

const localStorage = new Storage()

export const set = <T>(key:string, value:T, expires=7):void => {
    localStorage.set(key, value, {exp : 3600 * 24 * expires})
}

export const get = <T>(key:string):T => {
    return localStorage.get(key)
}

export const remove = (key:string):void => {
    localStorage.delete(key)
}

export const clear = ():void => {
    localStorage.clear()
}

export const saveLocale = <T>(locale:T):void=>{
    localStorage.set('locale',locale)
}
export const getLocale = <T>():T=>{
    return localStorage.get('locale')
}

export const setSession =  (key:string, value:string):void => {
    window.sessionStorage.setItem(key, value)
}
export const getSession =  (key:string):string|null => {
    return window.sessionStorage.getItem(key)
}